#pragma once
#include "RBTree.h"

namespace ztb
{
	template<class K, class T>
	class MyMap
	{
		struct MapOFT
		{
			const K& operator()(const pair<K, T>& pa)
			{
				return pa.first;
			}
		};
	public:

		typedef typename RBTree<K, pair<const K, T>, MapOFT>::iterator iterator;
		typedef typename RBTree<K, pair<const K, T>, MapOFT>::const_iterator const_iterator;

		iterator begin()
		{
			return _Mt.begin();
		}
		iterator end()
		{
			return _Mt.end();
		}

		const_iterator begin()const
		{
			return _Mt.begin();
		}
		const_iterator end()const
		{
			return _Mt.end();
		}

		T& operator[](const T& key)
		{
			pair<iterator, bool> ret = Insert(make_pair(key, T()));
			return ret.first->second;
		}

		pair<iterator, bool> Insert(const pair<K, T>& key)
		{
			return _Mt.Insert(key);
		}
	private:
		RBTree<K, pair<const K, T>, MapOFT> _Mt;
	};
}